package com.tito.common.api;




import com.tito.common.util.CollectionUtils;

import java.util.Collections;
import java.util.List;

/**
 * 自定义一套，主要用于controller与service层传参和对外，微服务架构传参等。
 * @param <T>
 */
public class PageInfo<T>
{
    private List<T> records;
    private long total;
    private long size;
    private long current;
    private String[] ascs;
    private String[] descs;


    public PageInfo()
    {
        this.records = Collections.emptyList();
        this.total = 0L;
        this.size = 10L;
        this.current = 1L;
    }

    public PageInfo(long current, long size)
    {
        this(current, size, 0L);
    }

    public PageInfo(long current, long size, long total)
    {
        this.records = Collections.emptyList();
        this.total = 0L;
        this.size = 10L;
        this.current = 1L;
        if (current > 1L)
        {
            this.current = current;
        }

        this.size = size;
        this.total = total;
    }

    public List<T> getRecords()
    {
        return this.records;
    }

    public PageInfo<T> setRecords(List<T> records)
    {
        this.records = records;
        return this;
    }

    public long getTotal()
    {
        return this.total;
    }

    public PageInfo<T> setTotal(long total)
    {
        this.total = total;
        return this;
    }

    public long getSize()
    {
        return this.size;
    }

    public PageInfo<T> setSize(long size)
    {
        this.size = size;
        return this;
    }

    public long getCurrent()
    {
        return this.current;
    }

    public PageInfo<T> setCurrent(long current)
    {
        this.current = current;
        return this;
    }

    public String[] ascs()
    {
        return this.ascs;
    }

    public PageInfo<T> setAscs(List<String> ascs)
    {
        if (CollectionUtils.isNotEmpty(ascs))
        {
            this.ascs = (String[]) ascs.toArray(new String[0]);
        }

        return this;
    }

    public PageInfo<T> setAsc(String... ascs)
    {
        this.ascs = ascs;
        return this;
    }

    public String[] descs()
    {
        return this.descs;
    }

    public PageInfo<T> setDescs(List<String> descs)
    {
        if (CollectionUtils.isNotEmpty(descs))
        {
            this.descs = (String[]) descs.toArray(new String[0]);
        }

        return this;
    }

    public PageInfo<T> setDesc(String... descs)
    {
        this.descs = descs;
        return this;
    }
}
